<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>新增便民电话</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <link rel="stylesheet" href="../css/font.css">
        <link rel="stylesheet" href="../css/xadmin.css">
        <script type="text/javascript" src="../assets/js/jquery-1.8.3.min.js"></script>
        <script src="../lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../js/xadmin.js"></script>
    
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <div class="layui-form" style="margin-left: 30%">
                    <div class="layui-form-item">
                        <label class="layui-form-label">
                            <span class="x-red">*</span>电话号</label>
                        <div class="layui-input-inline">
                            <input type="text" id="pphone" maxlength="11" name="username" required="" lay-verify="nikename" autocomplete="off" class="layui-input"></div>
                    </div>
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>姓名</label>
                        <div class="layui-input-inline">
                            <input type="text" id="pname" maxlength="5" autocomplete="off" class="layui-input"></div>
                    </div>
					<!--<div class="layui-form-item">
					    <label for="L_username" class="layui-form-label">
					        <span class="x-red">*</span>性别</label>
					    <div class="layui-input-inline">
					        <input type="text" id="psex" name="username" required="" lay-verify="nikename" autocomplete="off" class="layui-input"></div>
					</div>-->
                    <div class="layui-form-item">
                        <label for="L_username" class="layui-form-label">
                            <span class="x-red">*</span>性别</label>
                        <div class="layui-inline layui-show-xs-block">
                            <select name="cateid" id="psex">
                                <option>性别类型</option>
                                <option>男</option>
                                <option>女</option>
                            </select>
                        </div>
                    </div>
					<div class="layui-form-item">
					    <label for="L_username" class="layui-form-label">
					        <span class="x-red">*</span>年龄</label>
					    <div class="layui-input-inline">
					        <input type="text" id="page" maxlength="3"  autocomplete="off" class="layui-input"></div>
					</div>
					<div class="layui-form-item">
					    <label for="L_username" class="layui-form-label">
					        <span class="x-red">*</span>职位</label>
					    <div class="layui-inline layui-show-xs-block">
					        <select name="cateid" id="zw">
					          <option value="0">职位分类</option>
					          <option value="1">社区服务站站长</option>
					          <option value="2">社会福利与劳动保障专职工作者</option>
					          <option value="3">人口庄计生与公共卫生专职工作者</option>
                                <option value="4">社区治安综合治理专职工作者</option>
                                <option value="5">社区环境环保专职工作者</option>
                                <option value="6">社区公共文化专职工作者</option>
                                <option value="7">社区综合事务专职工作者</option>
					        </select>
					    </div>
					</div>
                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="add" id="butt" lay-submit="">增加</button></div>
                </div>
            </div>
        </div>
    </body>
</html>
<script>
    layui.use(['table', 'jquery','layer'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        var layer=layui.layer;

        $("#butt").click(function () {
            let pphone = $("#pphone").val();
            let pname = $("#pname").val();
            let psex = $("#psex option:selected").text();
            let page = $("#page").val();
            let zw = $("#zw option:selected").val();
            let flag = true;
            if (pphone == "" || pname == ""  || page == "" ||zw=="职位分类") {
                layer.msg('便民电话信息填写完整!', {
                    icon: 2, time: 800
                });
                flag = false;
            }
            var phone = /^1[3|4|5|8][0-9]\d{4,8}$/;
            if (flag) {
                if (!phone.test(pphone)) {
                    layer.msg('请输入正确的手机号码!', {
                        icon: 2, time: 800
                    });
                    flag = false;
                }
            }
            var r = /^\+?[1-9][0-9]*$/;　　//判断是否为正整数
            if (flag) {
                if (!r.test(page)) {
                    layer.msg('请输入正确的年龄!', {
                        icon: 2, time: 800
                    });
                    flag = false;
                }
            }
            if (flag) {
                $.ajax({
                    type:'POST',
                    url: "http://localhost:8080/api/bmdhinsert",
                    data: {
                        "pPhone": pphone,
                        "pName": pname,
                        "pSex": psex,
                        "pAge": page,
                        "pPosition": zw
                    },
                    headers: {
                        token: localStorage.getItem("token")
                    },
                    datatype: "json",
                    success: function (data) {
                        if (data.phone==0){
                            layer.msg('电话已存在!',{
                                icon:1
                                ,time:1000
                            });
                        }else {
                            var index = parent.layer.getFrameIndex(window.name);
                            layer.msg('增加成功!',{
                                icon:1
                                ,time:1000
                            },function (){
                                parent.layer.close(index);//关闭当前页
                            });
                        }
                    }
                })

            }
        })
    })
</script>